//
//  TemplateFoundDetailsModel.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/7/16.
//

#import "TemplateFoundDetailsModel.h"

@implementation TemplateFoundDetailsModel
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{@"ID":@[@"id"],
             @"Description":@[@"description"],
    };
}

+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{
        @"stepModelList":[TemplateFoundDetailsStepModelListModel class],
    };
}

-(BOOL)isLastModel{
    return self.stepModelList.lastObject.isSeled;
}

///选中另一个步骤
- (void)setSeledModel:(TemplateFoundDetailsStepModelListModel *)model{
    for (TemplateFoundDetailsStepModelListModel * smodel in self.stepModelList) {
        smodel.isSeled = NO;
    }
    model.isSeled = YES;
}
- (TemplateFoundDetailsStepModelListModel *)seledModel{
    for (TemplateFoundDetailsStepModelListModel * smodel in self.stepModelList) {
        if(smodel.isSeled){
            return smodel;
        }
    }
    self.stepModelList.firstObject.isSeled = YES;
    return self.stepModelList.firstObject;
}
-(NSString *)TjAPiHUDString{
    for (TemplateFoundDetailsStepModelListModel * model in self.stepModelList) {
        if([model TjAPiHUDString].length > 0){
            return [model TjAPiHUDString];
        }
    }
    return @"";
}
- (NSMutableDictionary *)TjDict {
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    if(self.templateId.length  > 0){///是个人模版-修改
        [dict setObject:self.templateId forKey:@"templateId"];
        [dict setObject:self.templateName forKey:@"templateName"];
        [dict setObject:self.ID forKey:@"id"];
        [dict setObject:self.name forKey:@"name"];
        [dict setObject:@([self.version intValue]) forKey:@"templateVersionNumber"];
        
    } else { ///公共模版--新增
        [dict setObject:self.ID forKey:@"templateId"];
        [dict setObject:self.templateName forKey:@"templateName"];
        [dict setObject:self.name forKey:@"name"];
        [dict setObject:@([self.version intValue]) forKey:@"templateVersionNumber"];

    }
    
    NSMutableArray * stepModelList = [NSMutableArray array];
    for (TemplateFoundDetailsStepModelListModel * model in self.stepModelList) {
        [stepModelList addObject:[model TjDictWithNew:(self.templateId.length == 0)]];
    }
    [dict setObject:stepModelList forKey:@"stepModelList"];
    
    return dict;
}


@end

///模板任务步骤详情
@implementation TemplateFoundDetailsStepModelListModel
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{@"ID":@[@"id"],
    };
}
+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{
        @"taskTypeModelList":[TemplateFoundDetailsTaskTypeModelListModel class],
    };
}
- (NSMutableArray<TemplateFoundDetailsTaskTypeModelListModel *> *)taskTypeModelList{
    if(![_taskTypeModelList isKindOfClass:NSMutableArray.class]){
        _taskTypeModelList = [NSMutableArray arrayWithArray:_taskTypeModelList];
    }
    return _taskTypeModelList;
}

- (CGFloat)nameW{
    if(_nameW == 0){
        _nameW = [DTKTool textWithtitle:self.name andSize:CGSizeMake(10000, 100) andFout:kCFont(17)].width + kwt(46);
    }
    return _nameW;
}

///判断同类型任务排序
- (int)ItemModelListIndexWithmodel:(TemplateFoundDetailsTaskTypeModelListModel *)model {
    int i = 1;
    for (TemplateFoundDetailsTaskTypeModelListModel * oldmodel in self.taskTypeModelList) {
        if([oldmodel.ID isEqualToString:model.ID]){
            if(oldmodel == model){
                return i;
            }
            i++;
        }
    }
    return i;
}
-(NSString *)TjAPiHUDString{
    for (TemplateFoundDetailsTaskTypeModelListModel * model in self.taskTypeModelList) {
        if([model TjAPiHUDString].length > 0){
            return [NSString stringWithFormat:@"%@->%@",self.name,[model TjAPiHUDString]];
        }
    }
    return @"";
}
- (NSMutableDictionary *)TjDictWithNew:(BOOL)isNew{
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    if(isNew){///公共模版--新增
        [dict setObject:self.ID forKey:@"templateStepId"];
        [dict setObject:self.name forKey:@"name"];
    } else { ///是个人模版-修改
        [dict setObject:self.templateStepId forKey:@"templateStepId"];
        [dict setObject:self.name forKey:@"name"];
        [dict setObject:self.ID forKey:@"id"];
    }
    [dict setObject:@(self.sort) forKey:@"sort"];
    NSMutableArray * taskTypeModelList = [NSMutableArray array];
    for (TemplateFoundDetailsTaskTypeModelListModel * model in self.taskTypeModelList) {
        [taskTypeModelList addObject:[model TjDictWithNew:isNew]];
    }
    [dict setObject:taskTypeModelList forKey:@"taskTypeModelList"];
    
    return dict;
}
- (NSMutableDictionary *)TjDictWithXG:(BOOL)isNew{
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    
    [dict setObject:self.templateStepId forKey:@"templateStepId"];
    [dict setObject:self.name forKey:@"name"];
    [dict setObject:self.ID forKey:@"id"];
    if(self.templateStepId.length < 1){
        [dict setObject:self.ID forKey:@"templateStepId"];
    }
    [dict setObject:@(self.sort) forKey:@"sort"];
    NSMutableArray * taskTypeModelList = [NSMutableArray array];
    for (TemplateFoundDetailsTaskTypeModelListModel * model in self.taskTypeModelList) {
        [taskTypeModelList addObject:[model TjDictWithXG:isNew]];
    }
    [dict setObject:taskTypeModelList forKey:@"taskTypeModelList"];
    
    return dict;
}

@end

///模板任务类型详情
@implementation TemplateFoundDetailsTaskTypeModelListModel
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{@"ID":@[@"id"],
             @"Description":@[@"description"],
    };
}

+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{
        @"executeModelList":[TemplateFoundDetailsExecuteModelListModel class],
        @"taskItemModelList":[TemplateFoundDetailsTaskItemModelListModel class],
    };
}
- (NSAttributedString *)nameStr{
    if(!_nameStr){
        _nameStr =  [DTKTool AttributedStringWithStr:self.name andNodeColor:KcolorHex(@"#222222") andSeledColor:KcolorHex(@"#222222") andNodeFont:kCFont(19) andFont:kFont(19) andPattenr:@""];

    }
    return _nameStr;
}
-(NSMutableArray <PondUserModel *>*)appointorArray{
    if(!_appointorArray){
        _appointorArray = [NSMutableArray array];
    }
    return _appointorArray;
}
-(NSMutableArray<TemplateFoundDetailsExecuteModelListModel *> *)executeModelList{
    if(![_executeModelList isKindOfClass:NSMutableArray.class]){
        _executeModelList = [NSMutableArray arrayWithArray:_executeModelList];
    }
    return _executeModelList;
}
-(NSMutableArray<TemplateFoundDetailsTaskItemModelListModel *> *)taskItemModelList{
    if(![_taskItemModelList isKindOfClass:NSMutableArray.class]){
        _taskItemModelList = [NSMutableArray arrayWithArray:_taskItemModelList];
    }
    return _taskItemModelList;
}
- (NSMutableArray<pondModelListModel *> *)pondModelListModel{
    if(!_pondModelListModel){
        _pondModelListModel = [NSMutableArray array];
    }
    return _pondModelListModel;
}
- (TemplateFoundDetailsTaskItemModelListModel *)XJtaskItemModel{
    for (TemplateFoundDetailsTaskItemModelListModel * model in self.taskItemModelList) {
        if(model.pattern == 1){
            for (TemplateFoundDetailsItemModelListModel * listModel in model.itemModelList) {///选项
                if(listModel.itemList.count > 0){///有子选项
                    return model;
                }
            }
        }
    }
    return nil;
}
- (CGFloat)haederViewH{
    if(self.isSQ){
        return kwt(45);
    }
    if(self.taskType == 2){
        return kwt(45 + 63);
    } else {
        if(self.executeType == 1){///1:自定义天数
            return kwt(45 * 2 + 63 + 63 + 20) + self.rateTimeViewH;
        } else {/// 2:整个养殖周期
            return kwt(45 * 2 + 63 + 20) + self.rateTimeViewH;
        }
    }
}
- (CGFloat)footerViewH{
    if(self.isSQ){
        return kwt(10);
    } else {
        return kwt(155);
    }
}
- (CGFloat)rateTimeViewH{
    _rateTimeViewH = ceil(self.rateNumber / 4.0) * kwt(53) - kwt(5);
    return _rateTimeViewH;
}
- (void)TimeArrayReload{
    self.executeModelList = [self.executeModelList sortedArrayUsingSelector:@selector(comparePerson:)];
    NSMutableArray<TemplateFoundDetailsExecuteModelListModel *> * newexecuteModelList = [NSMutableArray array];
    for (NSInteger i = 0; i < self.rateNumber; i++) {
        if(self.executeModelList.count > i){
            [newexecuteModelList addObject:self.executeModelList[i]];
        } else {
            [newexecuteModelList addObject:[TemplateFoundDetailsExecuteModelListModel new]];
        }
    }
    self.executeModelList = newexecuteModelList;
}
-(NSString *)TjAPiHUDString{
    if(self.taskType == 1){
        if(self.executeModelList.count < 1){
            return [NSString stringWithFormat:@"%@任务执行时间未选择",self.name];
        }
        for (TemplateFoundDetailsExecuteModelListModel * model in self.executeModelList) {///先判断时间
//            if(self.executeType == 1){
                if(model.executeTime.length < 1){
                    return [NSString stringWithFormat:@"%@任务执行时间未选择",self.name];
                }
//            }
        }
    }    
    for (TemplateFoundDetailsTaskItemModelListModel * model in self.taskItemModelList) {
        if([model TjAPiHUDString].length > 0){
            return [NSString stringWithFormat:@"%@->%@",self.name,[model TjAPiHUDString]];
        }
    }
    return @"";
}

- (NSMutableDictionary *)TjDictWithNew:(BOOL)isNew{
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    if(isNew){///公共模版--新增
        if(self.ID.length > 0){
            [dict setObject:self.ID forKey:@"templateTasktypeId"];
        } else {
            [dict setObject:self.templateTasktypeId forKey:@"templateTasktypeId"];
        }
        [dict setObject:self.name forKey:@"name"];
    } else { ///是个人模版-修改
        [dict setObject:self.templateTasktypeId forKey:@"templateTasktypeId"];
        [dict setObject:self.name forKey:@"name"];
        [dict setObject:self.ID forKey:@"id"];
    }
    if(self.cancelEndDay.length > 0){
        [dict setObject:self.cancelEndDay forKey:@"cancelEndDay"];
    }
    if(self.cancelEndDay.length > 0){
        [dict setObject:self.cancelStartDay forKey:@"cancelStartDay"];
    }
    ///必填
    [dict setObject:@(self.sort) forKey:@"sort"];
    [dict setObject:@(self.sortOut) forKey:@"sortOut"];
    [dict setObject:@(self.executeType) forKey:@"executeType"];
    
    [dict setObject:@(self.taskType) forKey:@"taskType"];
    
    [dict setObject:@(self.sourceFlag) forKey:@"sourceFlag"];
    [dict setObject:@(self.startDay) forKey:@"startDay"];
    [dict setObject:@(self.endDay) forKey:@"endDay"];
    [dict setObject:@(self.rateDay) forKey:@"rateDay"];
    [dict setObject:@(self.rateNumber) forKey:@"rateNumber"];
    [dict setObject:self.Description forKey:@"description"];
    [dict setObject:self.commonId forKey:@"commonId"];
    [dict setObject:self.videoUrl forKey:@"videoUrl"];
    ///用户-设置工作需要使用
    if(self.appointorArray.count > 0){
        NSMutableArray * appointorId = [NSMutableArray array];
        NSMutableArray * appointorName = [NSMutableArray array];
        for (PondUserModel * model in self.appointorArray) {
            [appointorId addObject:model.userId];
            [appointorName addObject:model.realName];
            
        }
        [dict setObject:[appointorId componentsJoinedByString:@","] forKey:@"appointorId"];
        [dict setObject:[appointorName componentsJoinedByString:@","] forKey:@"appointorName"];
        
    }
    
    
    NSMutableArray * executeModelList = [NSMutableArray array];
    for (TemplateFoundDetailsExecuteModelListModel * model in self.executeModelList) {///先判断时间
        if(model.executeTime.length > 0){
            [executeModelList addObject:[model TjDictWithNew:isNew]];
        }
    }
    [dict setObject:executeModelList forKey:@"executeModelList"];
    
    NSMutableArray * taskItemModelList = [NSMutableArray array];
    for (TemplateFoundDetailsTaskItemModelListModel * model in self.taskItemModelList) {
        [taskItemModelList addObject:[model TjDictWithNew:isNew]];
    }
    [dict setObject:taskItemModelList forKey:@"taskItemModelList"];
    
    return dict;
}
- (NSMutableDictionary *)TjDictWithXG:(BOOL)isNew{
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
       
   
    [dict setObject:self.templateTasktypeId forKey:@"templateTasktypeId"];
    [dict setObject:self.name forKey:@"name"];
    if(isNew == NO){
        [dict setObject:self.ID forKey:@"id"];
    } else {
        [dict setObject:self.ID forKey:@"templateTasktypeId"];
    }
    if(self.cancelEndDay.length > 0){
        [dict setObject:self.cancelEndDay forKey:@"cancelEndDay"];
    }
    if(self.cancelEndDay.length > 0){
        [dict setObject:self.cancelStartDay forKey:@"cancelStartDay"];
    }
    ///必填
    [dict setObject:@(self.sort) forKey:@"sort"];
    [dict setObject:@(self.sortOut) forKey:@"sortOut"];
    [dict setObject:@(self.executeType) forKey:@"executeType"];
    
    [dict setObject:@(self.taskType) forKey:@"taskType"];
    
    [dict setObject:@(self.sourceFlag) forKey:@"sourceFlag"];
    [dict setObject:@(self.startDay) forKey:@"startDay"];
    [dict setObject:@(self.endDay) forKey:@"endDay"];
    [dict setObject:@(self.rateDay) forKey:@"rateDay"];
    [dict setObject:@(self.rateNumber) forKey:@"rateNumber"];
    [dict setObject:self.Description forKey:@"description"];
    [dict setObject:self.commonId forKey:@"commonId"];
    [dict setObject:self.videoUrl forKey:@"videoUrl"];
    
    ///用户-设置工作需要使用
    if(self.appointorArray.count > 0){
        NSMutableArray * appointorId = [NSMutableArray array];
        NSMutableArray * appointorName = [NSMutableArray array];
        for (PondUserModel * model in self.appointorArray) {
            [appointorId addObject:model.userId];
            [appointorName addObject:model.realName];
            
        }
        [dict setObject:[appointorId componentsJoinedByString:@","] forKey:@"appointorId"];
        [dict setObject:[appointorName componentsJoinedByString:@","] forKey:@"appointorName"];
        
    }
    
    
    NSMutableArray * executeModelList = [NSMutableArray array];
    for (TemplateFoundDetailsExecuteModelListModel * model in self.executeModelList) {///先判断时间
        if(model.executeTime.length > 0){
            [executeModelList addObject:[model TjDictWithNew:isNew]];
        }
    }
    [dict setObject:executeModelList forKey:@"executeModelList"];
    
    NSMutableArray * taskItemModelList = [NSMutableArray array];
    for (TemplateFoundDetailsTaskItemModelListModel * model in self.taskItemModelList) {
        [taskItemModelList addObject:[model TjDictWithXG:isNew]];
    }
    [dict setObject:taskItemModelList forKey:@"taskItemModelList"];
    
    return dict;
}
- (NSString *)TjRWAPiHUDString {
    
    for (TemplateFoundDetailsTaskItemModelListModel * model in self.taskItemModelList) {
        if([model TjAPiHUDString].length > 0){
            return [NSString stringWithFormat:@"%@->%@",self.name,[model TjAPiHUDString]];
        }
    }
    if(self.appointorArray.count < 1){
        return [NSString stringWithFormat:@"请选择%@的任务指派人",self.name];
    }
    if(self.taskType != 2){
        if(self.executeTime.length < 1){
            return [NSString stringWithFormat:@"请选择%@的任务执行时间",self.name];
        }
    }
    return @"";
}
- (NSMutableDictionary *)TjRWDict {
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    [dict setObject:self.templateTasktypeId forKey:@"templateTasktypeId"];
    [dict setObject:self.name forKey:@"name"];
    ///用户-设置工作需要使用
    if(self.appointorArray.count > 0){
        NSMutableArray * appointorId = [NSMutableArray array];
        NSMutableArray * appointorName = [NSMutableArray array];
        for (PondUserModel * model in self.appointorArray) {
            [appointorId addObject:model.userId];
            [appointorName addObject:model.realName];
            
        }
        [dict setObject:[appointorId componentsJoinedByString:@","] forKey:@"appointorId"];
        [dict setObject:[appointorName componentsJoinedByString:@","] forKey:@"appointorName"];
        
    }
    
    [dict setObject:self.Description forKey:@"description"];
    ///加秒
    [dict setObject:[NSString stringWithFormat:@"%@:00",self.executeTime] forKey:@"executeTime"];
    [dict setObject:@(self.sort) forKey:@"sort"];
    [dict setObject:@(self.sortOut) forKey:@"sortOut"];
    [dict setObject:self.commonId forKey:@"commonId"];
    [dict setObject:self.videoUrl forKey:@"videoUrl"];
    
    if(self.pondModelListModel.count > 1){
        [dict setObject:@(self.configureItem) forKey:@"configureItem"];
    } else {
        [dict setObject:@(0) forKey:@"configureItem"];//单池塘传0
    }
    //    if(self.configureItem == 2){///分别传鱼塘
    
    NSMutableArray * pondModelList = [NSMutableArray array];
    for (pondModelListModel * model in self.pondModelListModel) {
        if(self.pondModelListModel.count > 1){
            [pondModelList addObject:[model TjRWDict]];
        } else {///单池塘按照分别配置
            NSMutableDictionary * pondDict = [model TjRWDict];
            NSMutableArray * taskItemModelList = [NSMutableArray array];
            for (TemplateFoundDetailsTaskItemModelListModel * model in self.taskItemModelList) {
                [taskItemModelList addObject:[model TjRWDictWithNew]];
            }
            [pondDict setObject:taskItemModelList forKey:@"taskItemModelList"];
            [pondModelList addObject:pondDict];
        }
        
    }
    [dict setObject:pondModelList forKey:@"pondModelList"];
    
    //    } else {///统一只传任务
   
    if(self.configureItem == 1){
        NSMutableArray * taskItemModelList = [NSMutableArray array];
        for (TemplateFoundDetailsTaskItemModelListModel * model in self.taskItemModelList) {
            [taskItemModelList addObject:[model TjRWDictWithNew]];
        }
        [dict setObject:taskItemModelList forKey:@"taskItemModelList"];
    }
  
    //    }
    
    
    
    return dict;
}

-(int)configureItem{
    if(self.pondModelListModel.count <= 1 || _configureItem == 0){
        _configureItem = 1;
    }
    return _configureItem;
}

-(CGFloat)RWhaederViewH{
    if(self.isSQ || self.pondModelListModel.count <= 1){
        return kwt(45);
    } else {
        if(self.taskItemModelList.count < 1){
            return kwt(45);
        }
        if(self.configureItem == 2){//分别
            if(self.isBG){
                return kwt(142);
            }
            return kwt(110);
        } else {///统一配置
            return kwt(110);
        }
    }
}
- (CGFloat)RWfooterViewH{
    if(self.isSQ){
        return kwt(10);
    }
    CGFloat imgH = kwt(135);
    if(self.appointorArray.count > 3){
        imgH = kwt(225);
    }
    if(self.isBG){
        imgH += kwt(15);///表格在家15
    }
    return kwt(5 + 135 + 10) + imgH + kwt(10 + 55 + 20);
}
//是否是表格
- (BOOL)isBG{
    if(self.configureItem == 2){
        if(self.taskItemModelList.count < 3){
            for (TemplateFoundDetailsTaskItemModelListModel * model in self.taskItemModelList) {
                ////// 样式;1:多项选择 2:下单单选3:数字输入框4:单行文本 5:多行文本
                if(model.pattern == 1){
                    return NO;
                }
            }
            return YES;
        }
    }
    
    return NO;
}

- (void)AllPondAddTask{
    NSMutableArray * CopyPondModelListModel = self.CopyPondModelListModel;
    for (pondModelListModel * pond in CopyPondModelListModel) {//池塘
//        if(pond.taskItemModelList.count < 1){///么有任务的
            pond.taskItemModelList = [NSMutableArray arrayWithArray:self.CopyTaskItemModelList];
//        } else {
//            
//        }
    }
    self.pondModelListModel = CopyPondModelListModel;
}

-(NSMutableArray<pondModelListModel *> *)CopyPondModelListModel{
    NSMutableArray * CopyPondModelListModel = [NSMutableArray array];
    for (pondModelListModel * model in self.pondModelListModel) {
        pondModelListModel * newModel = [pondModelListModel yy_modelWithJSON:[model yy_modelToJSONObject]];
        [CopyPondModelListModel addObject:newModel];
    }
    
    return CopyPondModelListModel;
}

-(NSMutableArray<TemplateFoundDetailsTaskItemModelListModel *> *)CopyTaskItemModelList{
    NSMutableArray * CopyTaskItemModelList = [NSMutableArray array];
    for (TemplateFoundDetailsTaskItemModelListModel * model in self.taskItemModelList) {
        TemplateFoundDetailsTaskItemModelListModel * newModel = [TemplateFoundDetailsTaskItemModelListModel yy_modelWithJSON:[model yy_modelToJSONObject]];
        [CopyTaskItemModelList addObject:newModel];
    }
    
    return CopyTaskItemModelList;
}
@end
///模板执行时间详情
@implementation TemplateFoundDetailsExecuteModelListModel
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{@"ID":@[@"id"],
    };
}
- (int)IntExecuteTime{
    if(self.executeTime.length > 0){
        NSArray <NSString *>* timeArray = [self.executeTime componentsSeparatedByString:@":"];
        return timeArray.firstObject.intValue * 100 + timeArray.lastObject.intValue;
    } else {
        return 2500;
    }
}

-(NSComparisonResult)comparePerson:(TemplateFoundDetailsExecuteModelListModel *)person{
    // 默认按年龄排序
    NSComparisonResult result = [[NSNumber numberWithInt:self.IntExecuteTime] compare:[NSNumber numberWithInt:person.IntExecuteTime]];// 注意:基本数据类型要进行数据转换
    return result;
}



- (NSMutableDictionary *)TjDictWithNew:(BOOL)isNew{
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    ///时间数据只传数据
    [dict setObject:self.executeTime forKey:@"executeTime"];
    
    return  dict;
}

@end
///模板任务项详情
@implementation TemplateFoundDetailsTaskItemModelListModel
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{@"ID":@[@"id"],
    };
}
+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{
        @"childrenModelList":[TemplateFoundDetailsChildrenModelListModel class],
        @"itemModelList":[TemplateFoundDetailsItemModelListModel class],
    };
}
-(NSMutableArray<TemplateFoundDetailsItemModelListModel *> *)itemModelList{
    if(![_itemModelList isKindOfClass:NSMutableArray.class]){
        _itemModelList = [NSMutableArray arrayWithArray:_itemModelList];
    }
    return _itemModelList;
}

-(NSMutableArray<TemplateFoundDetailsChildrenModelListModel *> *)childrenModelList{
    if(![_childrenModelList isKindOfClass:NSMutableArray.class]){
        _childrenModelList = [NSMutableArray arrayWithArray:_childrenModelList];
    }
    return _childrenModelList;
}
- (NSString *)numberStr{
//    if(!_numberStr){
        if(self.pattern > 3){
            _numberStr = self.content;
        } else {
            NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
            formatter.numberStyle = NSNumberFormatterDecimalStyle;
            formatter.maximumFractionDigits = self.degree;
            formatter.minimumFractionDigits = self.degree;
            _numberStr = [formatter stringFromNumber:self.number];
        }
//    }
    return _numberStr;
}
- (NSMutableArray<TemplateFoundDetailsItemModelListModel *> *)SubsetitemModelList{
    if(!_SubsetitemModelList){
        _SubsetitemModelList = [NSMutableArray array];
        for (TemplateFoundDetailsItemModelListModel * model in self.itemModelList) {
            if(model.itemList.count > 0){
                [_SubsetitemModelList addObject:model];
            }
        }
    }
    return _SubsetitemModelList;
}

- (NSMutableArray<TemplateFoundDetailsItemModelListModel *> *)SubsetNoitemModelList{
    if(!_SubsetNoitemModelList){
        _SubsetNoitemModelList = [NSMutableArray array];
        for (TemplateFoundDetailsItemModelListModel * model in self.itemModelList) {
            if(model.itemList.count < 1){
                [_SubsetNoitemModelList addObject:model];
            }
        }
    }
    return _SubsetNoitemModelList;
}
- (NSString *)SubsetNoitemModelListStr{
    if(!_SubsetNoitemModelListStr){
        NSString * str = @"";
        for (TemplateFoundDetailsItemModelListModel * model in self.SubsetNoitemModelList) {
            if(str.length > 0){
                str = [NSString stringWithFormat:@"%@,%@",str,model.name];
            } else {
                str = model.name;
            }
        }
        _SubsetNoitemModelListStr = str;
    }
    return _SubsetNoitemModelListStr;
}
- (CGFloat)RWDXXZViewH{
    if(_RWDXXZViewH == 0){
        if(self.pattern == 1 ){
            ///开始计算多行数据
            CGFloat X = kwt(10);
            CGFloat Y = kwt(45);
            for (TemplateFoundDetailsItemModelListModel * itemModel in self.itemModelList) {
                if(X + itemModel.nameW> kwt(340)){
                    X = kwt(10);
                    Y += kwt(48);
                }
                
//                if(X == kwt(10) && itemModel == self.itemModelList.lastObject){
//                    Y += kwt(48);
//                }
                X += itemModel.nameW + kwt(14);
            }
            
            _RWDXXZViewH = Y + kwt(45);
            
//        } else if(self.pattern == 5 ){///单行样式
//            _RWDXXZViewH = kwt(145);
        } else{
            _RWDXXZViewH = kwt(45);
        }
    }
    return _RWDXXZViewH;
    
}
- (CGFloat)DKDXXZViewH{
    if(self.pattern == 1 ){
        _DKDXXZViewH = self.CellH;
        if(self.configureItem == 2){///分别配置
            ///子选项
            for (TemplateFoundDetailsItemModelListModel * itemModel in self.itemModelList) {
                if(itemModel.checkedFlag == 1){
                    if(itemModel.itemList.count > 0){///有选项
                        _DKDXXZViewH += itemModel.itemListViewH;
                    }
                }
            }
        } else if(self.configureItem == 1){///统一
            _DKDXXZViewH = 0;
            for (TemplateFoundDetailsItemModelListModel * itemModel in self.itemModelList) {
                if(itemModel.checkedFlag == 1){
                    if(itemModel.itemList.count > 0){///有选项
                        _DKDXXZViewH += itemModel.itemListViewH;
                    }
                }
            }
        }
    } else if( self.pattern == 5){
        _DKDXXZViewH = kwt(145);
    } else {
        _DKDXXZViewH = kwt(63);
    }
    return _DKDXXZViewH;
}
- (CGFloat)TYDKDXXZViewH{//打卡
    if(_TYDKDXXZViewH == 0){
        CGFloat X = kwt(10);
        CGFloat Y = kwt(45);
        
        for (TemplateFoundDetailsItemModelListModel * itemModel in self.itemModelList) {
            if(X + itemModel.nameW> kwt(340)){
                X = kwt(10);
                Y += kwt(48);
            }
            
            if(X == kwt(10) && itemModel == self.itemModelList.lastObject){
                Y += kwt(48);
            }
            X += itemModel.nameW + kwt(14);
        }
        
        _TYDKDXXZViewH = Y + kwt(45 + 10);
    }
    return _TYDKDXXZViewH;
}
-(CGFloat)CellH{
    if(_CellH == 0){
        if(self.pattern == 1 ){
            ///开始计算多行数据
            CGFloat X = kwt(10);
            CGFloat Y = kwt(45);
            for (TemplateFoundDetailsItemModelListModel * itemModel in self.itemModelList) {
                if(X + itemModel.nameW > kwt(340)){
                    X = kwt(10);
                    Y += kwt(48);
                }
                X += itemModel.nameW + kwt(14);
            }
            _CellH = Y + kwt(45 + 10);
        } else if( self.pattern == 2 || self.pattern == 3 || self.pattern == 4){
            _CellH = kwt(63);
        } else if( self.pattern == 5){
            _CellH = kwt(145);
        }
    }
    
    return _CellH;
}
- (CGFloat)DKCellH{
    if(self.pattern == 1){
        CGFloat H = 0;
        for (TemplateFoundDetailsItemModelListModel * itemModel in self.itemModelList) {
            if(itemModel.checkedFlag == 1){
                if(itemModel.itemList.count > 1){///多个任务
                    H += itemModel.itemListViewH;
                } else {
                    for (TemplateFoundDetailsItemListModel * allModel in itemModel.itemList) {
                        H += allModel.viewH;
                    }
                }
            }
        }
        return self.CellH + H;
    } else if(self.pattern == 2){
        CGFloat H = 0;
        for (TemplateFoundDetailsItemModelListModel * itemModel in self.itemModelList) {
            if(itemModel.checkedFlag == 1){
                if(itemModel.itemList.count > 1){///多个任务
                    H += itemModel.itemListViewH;
                } else {
                    for (TemplateFoundDetailsItemListModel * allModel in itemModel.itemList) {
                        H += allModel.viewH;
                    }
                }
            }
        }
        return self.CellH + H;
    }
    return self.CellH;
}
- (TemplateFoundDetailsItemModelListModel *)itemSeledModel{
    if(self.pattern == 2){
        for (TemplateFoundDetailsItemModelListModel * itemModel in self.itemModelList) {
            if(itemModel.checkedFlag == 1){
                return itemModel;
            }
        }
    }
    return nil;
}
-(NSString *)TjAPiHUDString{
    if(self.forceFlag == 1){//必填
        /// 样式;1:多项选择 2:下单单选3:数字输入框4:单行文本 5:多行文本
        if(self.pattern == 1 || self.pattern == 2){
            BOOL isSeled = NO;
            for (TemplateFoundDetailsItemModelListModel * itemModel in self.itemModelList) {
                if(itemModel.checkedFlag == 1){
                    if(itemModel.itemList.count > 1){
                        BOOL listisSeled = NO;
                        for (TemplateFoundDetailsItemListModel * listitemModel in itemModel.itemList) {
                            if(itemModel.checkedFlag == 1){
                                listisSeled = YES;
                            }
                        }
                        if(listisSeled == NO){
                            return [NSString stringWithFormat:@"%@-%@未选择",self.name,itemModel.name];
                        }
                    }
                    isSeled = YES;
                }
            }
            if(isSeled == NO){
                return [NSString stringWithFormat:@"%@未选择",self.name];
            }
        } else if(self.pattern == 4 || self.pattern == 5){
            if(self.content.length < 0){
                return [NSString stringWithFormat:@"%@未填写",self.name];
            }
        }
    }
    return @"";
}

- (NSMutableDictionary *)TjDictWithNew:(BOOL)isNew{
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    if(isNew){///公共模版--新增
        if(self.ID.length > 0){
            [dict setObject:self.ID forKey:@"templateTaskitemId"];
        } else {
            [dict setObject:self.templateTaskitemId forKey:@"templateTaskitemId"];
        }
    } else { ///是个人模版-修改
        [dict setObject:self.templateTaskitemId forKey:@"templateTaskitemId"];
        [dict setObject:self.ID forKey:@"id"];
    }
    [dict setObject:self.name forKey:@"name"];
    [dict setObject:@(self.forceFlag) forKey:@"forceFlag"];
    [dict setObject:@(self.pattern) forKey:@"pattern"];
    [dict setObject:self.content forKey:@"content"];
    [dict setObject:@(self.sort) forKey:@"sort"];
    
    [dict setObject:@(self.numberMax) forKey:@"numberMax"];
    [dict setObject:@(self.numberMin) forKey:@"numberMin"];
    [dict setObject:@(self.degree) forKey:@"degree"];
    [dict setObject:@(self.stepValue) forKey:@"stepValue"];
    
    if(self.pattern == 3){
        [dict setObject:self.numberStr forKey:@"number"];
    }

    
    [dict setObject:self.templateItemId forKey:@"templateItemId"];
    
    NSMutableArray * itemModelList = [NSMutableArray array];
    for (TemplateFoundDetailsItemModelListModel * itemModel in self.itemModelList) {
        [itemModelList addObject:[itemModel TjDictWithNew:isNew]];
    }
    [dict setObject:itemModelList forKey:@"itemModelList"];
    
    return  dict;
}
- (NSMutableDictionary *)TjDictWithXG:(BOOL)isNew{
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    
    [dict setObject:self.templateTaskitemId forKey:@"templateTaskitemId"];
    if(isNew == NO){
        [dict setObject:self.ID forKey:@"id"];
    } else {
        [dict setObject:self.ID forKey:@"templateTaskitemId"];
    }
    [dict setObject:self.name forKey:@"name"];
    [dict setObject:@(self.forceFlag) forKey:@"forceFlag"];
    [dict setObject:@(self.pattern) forKey:@"pattern"];
    [dict setObject:self.content forKey:@"content"];
    [dict setObject:@(self.sort) forKey:@"sort"];
    
    [dict setObject:@(self.numberMax) forKey:@"numberMax"];
    [dict setObject:@(self.numberMin) forKey:@"numberMin"];
    [dict setObject:@(self.degree) forKey:@"degree"];
    [dict setObject:@(self.stepValue) forKey:@"stepValue"];
    
    if(self.pattern == 3){
        [dict setObject:self.numberStr forKey:@"number"];
    }

    
    [dict setObject:self.templateItemId forKey:@"templateItemId"];
    
    NSMutableArray * itemModelList = [NSMutableArray array];
    for (TemplateFoundDetailsItemModelListModel * itemModel in self.itemModelList) {
        [itemModelList addObject:[itemModel TjDictWithXG:isNew]];
    }
    [dict setObject:itemModelList forKey:@"itemModelList"];
    
    return  dict;
}

- (NSMutableDictionary *)TjRWDictWithNew{
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
   
    [dict setObject:self.templateTaskitemId forKey:@"templateTaskitemId"];
  
    [dict setObject:self.name forKey:@"name"];
    [dict setObject:@(self.forceFlag) forKey:@"forceFlag"];
    [dict setObject:@(self.pattern) forKey:@"pattern"];
    [dict setObject:self.content forKey:@"content"];
    [dict setObject:@(self.sort) forKey:@"sort"];
    
    [dict setObject:@(self.numberMax) forKey:@"numberMax"];
    [dict setObject:@(self.numberMin) forKey:@"numberMin"];
    [dict setObject:@(self.degree) forKey:@"degree"];
    [dict setObject:@(self.stepValue) forKey:@"stepValue"];
    
    if(self.pattern == 3){
        [dict setObject:self.numberStr forKey:@"number"];
    }

    
    [dict setObject:self.templateItemId forKey:@"templateItemId"];
    
    NSMutableArray * itemModelList = [NSMutableArray array];
    for (TemplateFoundDetailsItemModelListModel * itemModel in self.itemModelList) {
        [itemModelList addObject:[itemModel TjDictWithNew:YES]];
    }
    [dict setObject:itemModelList forKey:@"itemModelList"];
    
    return  dict;
}
- (CGFloat)DKDRWDYTViewH{
    if(self.isDRWSQ){
        for (TemplateFoundDetailsItemModelListModel * itemModel in self.itemModelList) {
            if(itemModel.checkedFlag == 1){
                return kwt(55 + 10);
            }
        }
        return 0;
    }else {///肯定是多任务
        CGFloat Y = kwt(55);
        if(self.pattern == 1){
            BOOL isHave = NO;
            for (TemplateFoundDetailsItemModelListModel * itemModel in self.itemModelList) {
                if(itemModel.checkedFlag == 1){
                    if(itemModel.itemListViewH > 0){///可能没有子任务
                        Y += itemModel.itemListViewH;
                        isHave = YES;
                    }
                }
            }
            if(Y > kwt(60)){///去一个间距
                Y -= kwt(10);
            }
            _DKDRWDYTViewH = Y + kwt(10);
            if(isHave == NO){///子任务没有任务直接不显示
                _DKDRWDYTViewH = 0;
            }
        } else if( self.pattern == 2){
            for (TemplateFoundDetailsItemModelListModel * itemModel in self.itemModelList) {
                if(itemModel.checkedFlag == 1){
                    Y += itemModel.itemListViewH;
                }
            }
            if(Y > kwt(60)){///去一个间距
                Y -= kwt(10);
            }
            _DKDRWDYTViewH = Y + kwt(8);
            if(_DKDRWDYTViewH == kwt(63)){///子任务没有任务直接不显示
                _DKDRWDYTViewH = 0;
            }

        } else if( self.pattern == 3 || self.pattern == 4){
            _DKDRWDYTViewH = Y + kwt(63);
        } else if( self.pattern == 5){
            _DKDRWDYTViewH = Y + kwt(145);
        }
        return _DKDRWDYTViewH;
    }
}
- (CGFloat)DKDRWDYTCellH{
    ///多任务多鱼塘cell搞的
    if(self.pattern == 1){
        ///开始计算多行数据
        CGFloat X = kwt(10);
        CGFloat Y = kwt(45);
        for (TemplateFoundDetailsItemModelListModel * itemModel in self.itemModelList) {
            if(X + itemModel.nameW> kwt(340)){
                X = kwt(10);
                Y += kwt(48);
            }
            X += itemModel.nameW + kwt(14);
        }
        _DKDRWDYTCellH = Y + kwt(48 + 10);
        for (pondModelListModel * pondmodel in self.pondModelList) {
            _DKDRWDYTCellH += [self modelWithPondModel:pondmodel].DKDRWDYTViewH;
        }
    } else if( self.pattern == 2){
        _DKDRWDYTCellH = kwt(63);
        for (TemplateFoundDetailsItemModelListModel * itemModel in self.itemModelList) {
            if(itemModel.checkedFlag == 1){
                if(itemModel.itemList.count > 0){
                    for (pondModelListModel * pondmodel in self.pondModelList) {
                        _DKDRWDYTCellH += [self modelWithPondModel:pondmodel].DKDRWDYTViewH;
                    }
                }
            }
        }
        return _DKDRWDYTCellH;
    } else if(self.pattern == 3 || self.pattern == 4){
        _DKDRWDYTCellH = kwt(63);

    } else if( self.pattern == 5){
        _DKDRWDYTCellH = kwt(145);
    }
    
    
    return _DKDRWDYTCellH;
}
///获取鱼塘下指定的任务model
- (TemplateFoundDetailsTaskItemModelListModel *)modelWithPondModel:(pondModelListModel *)model{
    for (pondModelListModel * pondModel in self.pondModelList) {
        if([pondModel.ID isEqualToString:model.ID]){
            for (TemplateFoundDetailsTaskItemModelListModel * itemModel in pondModel.taskItemModelList) {
                if([itemModel.templateTaskitemId isEqualToString:self.templateTaskitemId]){
                    return itemModel;
                }
            }
        }
    }
    return nil;
}

@end
///子任务项详情
@implementation TemplateFoundDetailsChildrenModelListModel
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{@"ID":@[@"id"],
    };
}

-(CGFloat)nameW{
    if(_nameW == 0){
        _nameW = [DTKTool textWithtitle:[NSString stringWithFormat:@"%@",self.name] andSize:CGSizeMake(10000, 1000) andFout:kFont(16)].width + kwt(20);
        if(_nameW > kwt(340)){
            _nameW = kwt(340);
        }
        if(_nameW < kwt(100)){
            _nameW = kwt(100);
        }
    }
    return _nameW;
}

- (nonnull NSMutableDictionary *)TjDictWithNew:(BOOL)isNew {
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    
    if(isNew){///新增
        if(self.ID.length > 0){
            [dict setObject:self.ID forKey:@"templateItemId"];
        } else {
            [dict setObject:self.templateItemId forKey:@"templateItemId"];
        }
    } else { ///是个人模版-修改
        [dict setObject:self.templateItemId forKey:@"templateItemId"];
        [dict setObject:self.ID forKey:@"id"];
    }
    
    [dict setObject:self.name forKey:@"name"];
    [dict setObject:@(self.sort) forKey:@"sort"];
    [dict setObject:@(self.checkedFlag) forKey:@"checkedFlag"];
    [dict setObject:self.templateItemId forKey:@"templateItemId"];
    
    return  dict;
}
- (nonnull NSMutableDictionary *)TjDictWithXG:(BOOL)isNew {
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    
    
    [dict setObject:self.templateItemId forKey:@"templateItemId"];
    if(![self.ID isEqualToString:self.templateItemId]){
        [dict setObject:self.ID forKey:@"id"];
    }
    if(self.templateItemId.length < 1){
        [dict setObject:self.ID forKey:@"templateItemId"];
    }
    
    [dict setObject:self.name forKey:@"name"];
    [dict setObject:@(self.sort) forKey:@"sort"];
    [dict setObject:@(self.checkedFlag) forKey:@"checkedFlag"];
    [dict setObject:self.templateItemId forKey:@"templateItemId"];
    
    return  dict;
}
@end

///选项配置内容详情
@implementation TemplateFoundDetailsItemModelListModel
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{@"ID":@[@"id"],
    };
}
+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{
        @"itemList":[TemplateFoundDetailsItemListModel class],
    };
}

-(NSMutableArray<TemplateFoundDetailsItemListModel *> *)itemList{
    if(![_itemList isKindOfClass:NSMutableArray.class]){
        _itemList = [NSMutableArray arrayWithArray:_itemList];
    }
    return _itemList;
}
-(CGFloat)itemListViewH{
    if(self.itemList.count > 0){
        if(self.itemList.count > 1){
            _itemListViewH = kwt(45 + 10);
            for (TemplateFoundDetailsItemListModel * model in self.itemList) {
                if(model.pattern == 1 ){
                    ///开始计算多行数据
                    CGFloat X = kwt(10);
                    CGFloat Y = kwt(45);
                    for (TemplateFoundDetailsChildrenModelListModel * itemModel in model.childrenModelList) {
                        if(X + itemModel.nameW> kwt(340)){
                            X = kwt(10);
                            Y += kwt(48);
                        }
                        X += itemModel.nameW + kwt(10);
                    }
                    _itemListViewH += Y + kwt(45);
                } else if( model.pattern == 2 || model.pattern == 3 || model.pattern == 4){
                    _itemListViewH += kwt(63 - 10);
                } else if( model.pattern == 5){
                    _itemListViewH += kwt(145 - 10);
                }
            }
        } else {
            for (TemplateFoundDetailsItemListModel * model in self.itemList) {
                if(model.pattern == 1 ){
                    ///开始计算多行数据
                    CGFloat X = kwt(10);
                    CGFloat Y = kwt(45);
                    for (TemplateFoundDetailsChildrenModelListModel * itemModel in model.childrenModelList) {
                        if(X + itemModel.nameW> kwt(340)){
                            X = kwt(10);
                            Y += kwt(48);
                        }
                        X += itemModel.nameW + kwt(10);
                    }
                    _itemListViewH = Y + kwt(45 + 10);
                } else if( model.pattern == 2 || model.pattern == 3 || model.pattern == 4){
                    _itemListViewH = kwt(63);
                } else if( model.pattern == 5){
                    _itemListViewH = kwt(145);
                }
            }
        }
        return _itemListViewH;
    }
    return 0;
}
-(CGFloat)nameW{
    if(_nameW == 0){
        _nameW = [DTKTool textWithtitle:[NSString stringWithFormat:@"%@",self.name] andSize:CGSizeMake(10000, 1000) andFout:kFont(16)].width + kwt(20);
        if(_nameW > kwt(340)){
            _nameW = kwt(330);
        }
        if(_nameW < kwt(100)){
            _nameW = kwt(100);
        }
    }
    return _nameW;
}

- (NSMutableDictionary *)TjDictWithNew:(BOOL)isNew{
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    if(isNew){///新增
        if(self.ID.length > 0){
            [dict setObject:self.ID forKey:@"templateItemId"];
        } else {
            [dict setObject:self.templateItemId forKey:@"templateItemId"];
        }
        
    } else { ///是个人模版-修改
        [dict setObject:self.templateItemId forKey:@"templateItemId"];
        [dict setObject:self.ID forKey:@"id"];
    }
    
    [dict setObject:@(self.checkedFlag) forKey:@"checkedFlag"];
    [dict setObject:self.name forKey:@"name"];
    [dict setObject:@(self.sort) forKey:@"sort"];
    NSMutableArray * itemList = [NSMutableArray array];
    for (TemplateFoundDetailsItemListModel * model in self.itemList) {
        [itemList addObject:[model TjDictWithNew:isNew]];
    }
    [dict setObject:itemList forKey:@"itemList"];
    
    
    return  dict;
}

- (NSMutableDictionary *)TjDictWithXG:(BOOL)isNew{
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    [dict setObject:self.templateItemId forKey:@"templateItemId"];
    if(isNew == NO){
        [dict setObject:self.ID forKey:@"id"];
    } else {
        [dict setObject:self.ID forKey:@"templateItemId"];
    }
    [dict setObject:@(self.checkedFlag) forKey:@"checkedFlag"];
    [dict setObject:self.name forKey:@"name"];
    [dict setObject:@(self.sort) forKey:@"sort"];
    NSMutableArray * itemList = [NSMutableArray array];
    for (TemplateFoundDetailsItemListModel * model in self.itemList) {
        [itemList addObject:[model TjDictWithXG:isNew]];
    }
    [dict setObject:itemList forKey:@"itemList"];
    
    
    return  dict;
}
@end

///下拉选项配置详情
@implementation TemplateFoundDetailsItemListModel
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{@"ID":@[@"id"],
    };
}

+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{
        @"childrenModelList":[TemplateFoundDetailsChildrenModelListModel class],
    };
}

-(NSMutableArray<TemplateFoundDetailsChildrenModelListModel *> *)childrenModelList{
    if(![_childrenModelList isKindOfClass:NSMutableArray.class]){
        _childrenModelList = [NSMutableArray arrayWithArray:_childrenModelList];
    }
    return _childrenModelList;
}
-(CGFloat)viewH{
    
    if(_viewH == 0){
        if(self.pattern == 1 ){
            ///开始计算多行数据
            CGFloat X = kwt(10);
            CGFloat Y = kwt(45);
            for (TemplateFoundDetailsChildrenModelListModel * itemModel in self.childrenModelList) {
                if(X + itemModel.nameW > kwt(340)){
                    X =  kwt(10);
                    Y += kwt(48);
                }
                X += itemModel.nameW + kwt(10);
            }
            _viewH = Y + kwt(45 + 10);
        } else if( self.pattern == 2 || self.pattern == 3 || self.pattern == 4){
            _viewH = kwt(63);
        } else if( self.pattern == 5){
            _viewH = kwt(145);
        }
    }
    
    return _viewH;
    
}
- (TemplateFoundDetailsChildrenModelListModel *)seledModel{
    if(self.pattern == 2){
        for (TemplateFoundDetailsChildrenModelListModel * itemModel in self.childrenModelList) {
            if(itemModel.checkedFlag == 1){
                return itemModel;
            }
        }
    }
    return nil;
}
- (NSMutableDictionary *)TjDictWithNew:(BOOL)isNew{
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    if(isNew){///新增
        [dict setObject:self.ID forKey:@"templateTaskitemId"];
    } else { ///是个人模版-修改
        [dict setObject:self.templateTaskitemId forKey:@"templateTaskitemId"];
        [dict setObject:self.ID forKey:@"id"];
    }
    
    [dict setObject:self.name forKey:@"name"];
    [dict setObject:@(self.forceFlag) forKey:@"forceFlag"];
    [dict setObject:@(self.pattern) forKey:@"pattern"];
    [dict setObject:self.content forKey:@"content"];
    [dict setObject:@(self.sort) forKey:@"sort"];
    
    [dict setObject:@(self.numberMax) forKey:@"numberMax"];
    [dict setObject:@(self.numberMin) forKey:@"numberMin"];
    [dict setObject:@(self.degree) forKey:@"degree"];
    [dict setObject:@(self.stepValue) forKey:@"stepValue"];
    if(self.pattern == 3){
        [dict setObject:self.numberStr forKey:@"number"];
    }
    [dict setObject:self.templateItemId forKey:@"templateItemId"];
    
    NSMutableArray * childrenModelList = [NSMutableArray array];
    for (TemplateFoundDetailsChildrenModelListModel * itemModel in self.childrenModelList) {
        [childrenModelList addObject:[itemModel TjDictWithNew:isNew]];
    }
    [dict setObject:childrenModelList forKey:@"childrenModelList"];
    
    return  dict;
}
- (NSMutableDictionary *)TjDictWithXG:(BOOL)isNew{
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    
    [dict setObject:self.templateTaskitemId forKey:@"templateTaskitemId"];
    if(isNew == NO){
        [dict setObject:self.ID forKey:@"id"];
    } else {
        [dict setObject:self.ID forKey:@"templateTaskitemId"];
    }
    [dict setObject:self.name forKey:@"name"];
    [dict setObject:@(self.forceFlag) forKey:@"forceFlag"];
    [dict setObject:@(self.pattern) forKey:@"pattern"];
    [dict setObject:self.content forKey:@"content"];
    [dict setObject:@(self.sort) forKey:@"sort"];
    
    [dict setObject:@(self.numberMax) forKey:@"numberMax"];
    [dict setObject:@(self.numberMin) forKey:@"numberMin"];
    [dict setObject:@(self.degree) forKey:@"degree"];
    [dict setObject:@(self.stepValue) forKey:@"stepValue"];
    if(self.pattern == 3){
        [dict setObject:self.numberStr forKey:@"number"];
    }
    [dict setObject:self.templateItemId forKey:@"templateItemId"];
    
    NSMutableArray * childrenModelList = [NSMutableArray array];
    for (TemplateFoundDetailsChildrenModelListModel * itemModel in self.childrenModelList) {
        [childrenModelList addObject:[itemModel TjDictWithXG:isNew]];
    }
    [dict setObject:childrenModelList forKey:@"childrenModelList"];
    
    return  dict;
}

- (NSString *)numberStr{
    if(!_numberStr){
        if(self.pattern > 3){
            _numberStr = self.content;
        } else {
            NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
            formatter.numberStyle = NSNumberFormatterDecimalStyle;
            formatter.maximumFractionDigits = self.degree;
            formatter.minimumFractionDigits = self.degree;
            _numberStr = [formatter stringFromNumber:self.number];
        }
    }
    return _numberStr;
}
- (NSString *)contentStr{
    if(!_contentStr){
        if(self.pattern > 3){
            _contentStr = self.content;
        } else if(self.pattern == 3){
            if(self.unitName.length > 0){
                _contentStr = self.unitName;
            } else {
                NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
                formatter.numberStyle = NSNumberFormatterDecimalStyle;
                formatter.maximumFractionDigits = self.degree;
                formatter.minimumFractionDigits = self.degree;
                _contentStr = [formatter stringFromNumber:self.number];
            }
        } else if(self.pattern == 2){
            for (TemplateFoundDetailsChildrenModelListModel * listmodel in self.childrenModelList) {
                if(listmodel.checkedFlag == 1){
                    _contentStr = self.childrenModelList.firstObject.name;
                }
            }
        } else if(self.pattern == 1){
            for (TemplateFoundDetailsChildrenModelListModel * listmodel in self.childrenModelList) {
                if(listmodel.checkedFlag == 1){
                    if(_contentStr.length > 0){
                        _contentStr = [NSString stringWithFormat:@"%@,%@",_contentStr,listmodel.name];
                    } else {
                        _contentStr = listmodel.name;
                    }
                }
            }
        }
    }
    return _contentStr;

}
@end
